import {
    wxRequest
} from '../../../utils/server.js';
const _wxRequest = new wxRequest();
const app = getApp()

Page({
    data: {
        datalist: [],
        orgName: '',
        keyword: '',
        isEdit: -1,
    },

    onLoad: function (options) {
        console.log(options,123123);
        this.data.orgName = options.orgName
        this.data.orgId = options.orgId
        this.data.orgType = options.orgType
        if (options) {
            this.data.isEdit = options.isEdit
            this.setData({
                isHide: options.hide
            })
        } else {
            this.setData({
                isHide: false
            })
        }
        this.getlist();
        
    },

    // 获取列表
    getlist: function () {
        var that = this
        var url = '/sys/protected/user/findEmployee'

        _wxRequest.wxTonkenAjax({
            url: app.globalData.apiUrl + url,
            method: "post",
            data: {
                orgName: this.data.orgName,
                orgId: this.data.orgId,
                orgType: this.data.orgType == 1 ? null : this.data.orgType,
                keyword: this.data.keyword
            }
        }, function (res) {
            console.log(res, 111111)
            that.setData({
                datalist: res.list
            })
        })
    },


    //监听搜索
    seacherOn: function (e) {
        var keyword = e.detail
        this.setData({
            keyword
        })
        this.getlist()
    },


    //选择供应商
    choose: function (e) {
        console.log('choose', e)
        var item = e.currentTarget.dataset.item

        //直接调用上一个页面的setData()方法，把数据存到上一个页面中去
        var pages = getCurrentPages();
        var prevPage = pages[pages.length - 2]; //上一个页面    
        prevPage.setData({
            staffItem: item,
        })
        if (this.data.isEdit == 0) {
            prevPage.setData({
                isEdit: false
            })
        }
        wx.navigateBack();
    },


})